// When color definition differs for dark and light variant,
// it gets @if ed depending on $variant

$higher_opacity: 0.87;
$middle_opacity: 0.54;
$lower_opacity: 0.24;

$enabled_opacity: 0.75;
$hint_opacity: 0.6;
$disabled_opacity: 0.4;

@function gtkalpha($c, $a) {
  @return unquote("alpha(#{$c}, #{$a})");
}

@function scale-alpha($c, $a) {
  @return scale-color($c, $alpha: percentage(-1 + $a));
}

// based color palette:
// https://material.google.com/style/color.html#color-color-palette
// based border and highlight values:
// https://material.google.com/style/icons.html#icons-product-icons

// Foreground colors
$light_contrast_color: scale-alpha(#000000, 0.8);
$dark_contrast_color: #FFFFFF;
$darker_contrast_color: #EAEAEA;
$darkest_contrast_color: #000000;

$fg_color: if($variant == 'light', $light_contrast_color, $darker_contrast_color);
$secondary_fg_color: scale-alpha($fg_color, $enabled_opacity);
$tertiary_fg_color: scale-alpha($fg_color, $hint_opacity);

$inversed_fg_color: $dark_contrast_color;
$secondary_inversed_fg_color: scale-alpha($inversed_fg_color, $enabled_opacity);
$tertiary_inversed_fg_color: scale-alpha($inversed_fg_color, $hint_opacity);

$disabled_fg_color: scale-alpha($fg_color, $disabled_opacity);
$disabled_secondary_fg_color: scale-alpha($secondary_fg_color, $disabled_opacity);
$disabled_tertiary_fg_color: scale-alpha($tertiary_fg_color, $disabled_opacity);

$disabled_inversed_fg_color: scale-alpha($inversed_fg_color, $disabled_opacity);
$disabled_secondary_inversed_fg_color: scale-alpha($secondary_inversed_fg_color, $disabled_opacity);
$disabled_tertiary_inversed_fg_color: scale-alpha($tertiary_inversed_fg_color, $disabled_opacity);

// Background colors
$bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #282828, #2c2e33), #F5F5F5);
$base_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #303030, #313338), #FFFFFF);
$alt_base_color: mix($base_color, $bg_color, 50%);

$lighter_bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #383838, #36393e), #FCFCFC);
$darker_bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #303030, #30333b), #EEEEEE);
$darker_fg_color: if($variant =='light', if($color == 'ruby' or $color == 'black' or $color == 'white', #222222, #212329), #DDDDDD);

// Headerbar colors
$headerbar_fg_color: if($headerbar =='dark', $darker_contrast_color, $fg_color);
$secondary_headerbar_fg_color: if($headerbar =='dark', $secondary_inversed_fg_color, $secondary_fg_color);
$disabled_headerbar_fg_color: if($headerbar =='dark', $disabled_secondary_inversed_fg_color, $disabled_fg_color);

$headerbar_bg_color: #eeeeee;
@if ($color == 'ruby' or $color == 'black') and $headerbar =='dark' { $headerbar_bg_color: if($variant =='light', #383838, #363636); }
@if ($color == 'doder' or $color == 'beryl' or $color == 'amethyst') and $headerbar =='dark' { $headerbar_bg_color: if($variant =='light', #36393e, #36383e); }

// Selected and Theme colors
$primary_color: #686868;
$alt_primary_color: #777777;
$accent_color: #666666;
@if $color == 'ruby'     { $primary_color: #F0544C; $alt_primary_color: #FF615A; $accent_color: #FF626C; }
@if $color == 'doder'    { $primary_color: #4285F4; $alt_primary_color: #03a9f4; $accent_color: #18b8ff; }
@if $color == 'beryl'    { $primary_color: #2EB398; $alt_primary_color: #1eba9b; $accent_color: #0fd1ab; }
@if $color == 'amethyst' { $primary_color: #892eb3; $alt_primary_color: #7c1eba; $accent_color: #a40fd1; }

@if $color == 'black' {
    $primary_color: if($variant =='light', #686868, #686868);
    $alt_primary_color: if($variant =='light', #777777, #777777);
    $accent_color: if($variant =='light', #666666, #888888); }

$theme_color: if($color == 'black', $dark_contrast_color, $primary_color);
$alt_theme_color: if($color == 'black', $dark_contrast_color, $accent_color);

$inverse_theme_color: if($color == 'black' and $variant =='dark', $dark_contrast_color, $primary_color);
$alt_inverse_theme_color: if($color == 'black' and $variant =='dark', $dark_contrast_color, $accent_color);

$topbar_theme_color: if($color == 'black' or $color =='white', $darker_contrast_color, $primary_color);
$alt_topbar_theme_color: if($color == 'black' and $color =='white', $darker_contrast_color, $accent_color);

$menu_bg_color: if($headerbar == 'light', $base_color, $headerbar_bg_color);
$menu_fg_color: if($headerbar == 'light', $secondary_fg_color, $secondary_headerbar_fg_color);
$disabled_menu_fg_color: rgba($menu_fg_color, 0.3);

$tab_color: $inverse_theme_color;
$secondary_titlebar_color: $primary_color;
$topbar_bg_color: #222222;
@if $color == 'ruby' or $color == 'black' { $topbar_bg_color: #222222; }
@if $color == 'doder' or $color == 'beryl' or $color == 'amethyst' { $topbar_bg_color: #212329; }
$topbar_fg_color: $dark_contrast_color;
$alt_topbar_fg_color: $darker_contrast_color;

// Misc colors
$track_color: gtkalpha(currentColor, $lower_opacity);
$high_track_color: gtkalpha(currentColor, $disabled_opacity);
$semi_track_color: gtkalpha(currentColor, $lower_opacity / 2);
$zero_track_color: gtkalpha(currentColor, 0);
$row_track_color: gtkalpha(currentColor, 0.05);
$borders_color: if($variant == 'light', scale-alpha(#000000, 0.1), scale-alpha(#000000, 0.18));
$solid_borders_color: if($variant == 'light', darken($bg_color, 10%), darken($bg_color, 2.5%));
$darker_borders_color: if($variant == 'light', darken($bg_color, 15%), darken($bg_color, 3.5%));
$highlight_color: if($variant == 'light', scale-alpha(#FFFFFF, 0.4), scale-alpha(#FFFFFF, 0.3));
$secondary_highlight_color: scale-alpha(#FFFFFF, 0.1);

$placeholder_text_color: mix($fg_color, $base_color, percentage($hint_opacity));

$warning_color: #FF6D00;
$error_color: #DD2C00;
$success_color: #00C853;

$suggested_color: #4CAF50;
$destructive_color: #FF5252;

$info_bg_color: #66BB6A;
$question_bg_color: #42A5F5;
$warning_bg_color: #FFA726;
$error_bg_color: #EF5350;

$link_color: if($color == 'black' or $color == 'white', $question_bg_color, $primary_color);
$link_visited_color: #E040FB;
